package com.shujia.scala

object Demo8CaseClass {
  def main(args: Array[String]): Unit = {
    val user1 = new User("001", "张三")
    //直接通过属性获取值
    println(user1.id)
    println(user1)

    //样例类可以不适用new创建对象
    val user2: User = User("002", "李四", 24)
    println(user2)

    //修改属性,需要在属性上增加var
    user2.name = "王五"
    println(user2)
  }
}

/**
 * 样例类
 * scala会在编译的时候给样例类动态增加新的方法，属性，toString，序列化
 *
 * age: Int = 0: 参数默认值
 */

case class User(id: String,var name: String, age: Int = 0)
